﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//New and needed
using System.Runtime.Serialization;
using System.Collections.ObjectModel;

namespace IM.Common.Message
{
    /// <summary>
    /// 
    /// </summary>
    /// <remarks>
    /// 
    /// </remarks>
    public class Response
    {

        [DataMember]
        private readonly long EntityIDInstance;


        [DataMember]
        private BusinessExceptionDTO BusinessExceptionInstance;

        [DataMember]
        private readonly IList<BusinessWarning> BusinessWarningListInstance = new List<BusinessWarning>();


        #region Public Constructors
        public Response(long entityID)
        { 
            //CJ_Comment: readonly access modifier allows to set this value only in constructors.
            EntityIDInstance = entityID;
        }

        public Response() : this(0) { }
        #endregion

        #region Public Methods
        public void AddBusinessException(BusinessException exception)
        {
            this.BusinessExceptionInstance = new BusinessExceptionDTO(exception.BusinessExceptionType, exception.Message, exception.StackTrace);
        }

        public void AddBusinessWarnings(IEnumerable<BusinessWarning> warnings)
        {
            warnings.ToList().ForEach(w => this.BusinessWarningListInstance.Add(w));
        }
        #endregion  


        public IEnumerable<BusinessWarning> BusinessWarnings
        {
            get { return new ReadOnlyCollection<BusinessWarning> (this.BusinessWarningListInstance);}
        }
        public long EntityID
        {
            get { return EntityIDInstance; }
        }

        public bool HasException
        {
            get { return this.BusinessExceptionInstance != null; }
        }

        public BusinessExceptionDTO BusinessException
        {
            get { return this.BusinessExceptionInstance; }
        }

    }
}
